package com.phonetools.commonutils.security

import java.security.KeyFactory
import java.security.PrivateKey
import java.security.PublicKey
import java.security.spec.PKCS8EncodedKeySpec
import java.security.spec.X509EncodedKeySpec

fun genRSAPrivateKey(input: ByteArray): PrivateKey =
    KeyFactory.getInstance("RSA")
        .generatePrivate(PKCS8EncodedKeySpec(input))

fun genRSAPrivateKey(input: String): PrivateKey =
    genRSAPrivateKey(base64Decode(input))

fun genRSAPublicKey(input: ByteArray): PublicKey =
    KeyFactory.getInstance("RSA")
        .generatePublic(X509EncodedKeySpec(input))

fun genRSAPublicKey(input: String): PublicKey =
    genRSAPublicKey(base64Decode(input))